# Maintainer: Alexey Pavlov <alexpux@gmail.com>
# Contributor: Ray Donnelly <mingw.android@gmail.com>

_realname=inkscape

pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=0.48.5
pkgrel=1
pkgdesc="Vector graphics editor using the SVG file format (mingw-w64)"
arch=('any')
url="http://inkscape.sourceforge.net/"
license=("GPL" "LGPL")
install=inkscape-${CARCH}.install
makedepends=("${MINGW_PACKAGE_PREFIX}-gcc"
            "${MINGW_PACKAGE_PREFIX}-pkg-config"
            "${MINGW_PACKAGE_PREFIX}-boost"
            "intltool")
depends=(
    "${MINGW_PACKAGE_PREFIX}-gc"
    "${MINGW_PACKAGE_PREFIX}-ghostscript"
    "${MINGW_PACKAGE_PREFIX}-gsl"
    "${MINGW_PACKAGE_PREFIX}-gtkmm"
    "${MINGW_PACKAGE_PREFIX}-gtkspell"
    "${MINGW_PACKAGE_PREFIX}-hicolor-icon-theme"
    "${MINGW_PACKAGE_PREFIX}-imagemagick"
    "${MINGW_PACKAGE_PREFIX}-lcms2"
    "${MINGW_PACKAGE_PREFIX}-libxml2"
    "${MINGW_PACKAGE_PREFIX}-libxslt"
    "${MINGW_PACKAGE_PREFIX}-libwpg"
    "${MINGW_PACKAGE_PREFIX}-poppler"
    "${MINGW_PACKAGE_PREFIX}-popt"
    "${MINGW_PACKAGE_PREFIX}-python2"
    )
optdepends=(#"${MINGW_PACKAGE_PREFIX}-pstoedit: latex formulas"
            #"${MINGW_PACKAGE_PREFIX}-texlive-core: latex formulas"
            "${MINGW_PACKAGE_PREFIX}-python2-numpy: some extensions"
            "${MINGW_PACKAGE_PREFIX}-python2-lxml: some extensions and filters"
            #"${MINGW_PACKAGE_PREFIX}-uniconvertor: reading/writing to some proprietary formats"
            )
options=('staticlibs' 'strip')
source=("http://downloads.sourceforge.net/project/${_realname}/${_realname}/${pkgver}/${_realname}-${pkgver}.tar.bz2"
        inkscape-0.48.4-gc74.patch
        inkscape-0.48.4-headers-fix.patch
        inkscape-0.48.4-python.patch
        inkscape-0.48.4-use-GStatBuf-insted-stat.patch
        inkscape-0.48.4-poppler-includes-conflicts.patch
        inkscape-0.48.4-mingw-dont-need-dl.patch
        inkscape-0.48.4-win32-relocatable.patch
        inkscape-0.48.4-win32-file-dialog.patch
        inkscape-0.48.4-python-extensions-location.patch
        ime-placement.patch)
sha1sums=('83ddb0c96069638f712a869039989bfd7d79c6a8'
          '764ec7166c0308a8defcbb450468f15d821929f2'
          '12fddb0a0b34b4308de1979d13b26d05a6ec8f77'
          '4dd0da65e538ba7e73a42ce76efd5e5a155d3bf0'
          '2606a83aa0b116e51883543c3aadce6f8c4c2565'
          '8d65767ed2b291ccae70d8718f0b7a764632c445'
          'db9c1ce6372e8670f9949d2aaef3d27f8ded32ec'
          '6a65e95e9d310b48b3caebc98f323183cef60e0c'
          'b4fe07272789c4cd121bcabbd9e3893acbac39fc'
          '185cd8f6e4ad0b55862720c47f80da9dfa8a82ff'
          'b12b948ca5ee7e02703a13aa8b8bccdf67947f12')

prepare() {
  cd "${srcdir}/${_realname}-${pkgver}"
  patch -p1 -i ${srcdir}/inkscape-0.48.4-gc74.patch
  patch -p1 -i ${srcdir}/inkscape-0.48.4-headers-fix.patch
  patch -p1 -i ${srcdir}/inkscape-0.48.4-python.patch
  patch -p1 -i ${srcdir}/inkscape-0.48.4-use-GStatBuf-insted-stat.patch
  patch -p1 -i ${srcdir}/inkscape-0.48.4-poppler-includes-conflicts.patch
  patch -p1 -i ${srcdir}/inkscape-0.48.4-mingw-dont-need-dl.patch
  patch -p1 -i ${srcdir}/inkscape-0.48.4-win32-relocatable.patch
  patch -p1 -i ${srcdir}/inkscape-0.48.4-win32-file-dialog.patch
  patch -p1 -i ${srcdir}/inkscape-0.48.4-python-extensions-location.patch
  patch -p1 -i ${srcdir}/ime-placement.patch
  
  sed -i 's|/usr/bin/python\>|/usr/bin/python2|g' cxxtest/*.py
  sed -i 's|/usr/bin/env python\>|/usr/bin/env python2|g' share/*/{test/,}*.py
  #sed -i 's|"python" },|"python2" },|g' src/extension/implementation/script.cpp
  sed -i 's|python -c|python2 -c|g' configure share/extensions/uniconv*.py
  sed -i '/^#include <g.kmm/i #include <glibmm.h>' src/*{,/*{,/*{,/*}}}.{h,cpp}
  sed -e "s|export-dynamic|export-all-symbols|g" -i src/Makefile.am
  
  autoreconf -fi -I m4
}

build() {
  # export lt_cv_deplibs_check_method='pass_all'
  rm -rf $srcdir/cd build-${MINGW_CHOST}
  mkdir -p build-${MINGW_CHOST} && cd build-${MINGW_CHOST}

  CPPFLAGS+=" -D__USE_MINGW_ANSI_STDIO=1"
  CFLAGS+=" -D__USE_MINGW_ANSI_STDIO=1"
  CXXFLAGS+=" -D__USE_MINGW_ANSI_STDIO=1"
  ../${_realname}-${pkgver}/configure \
    --prefix=${MINGW_PREFIX} \
    --build=${MINGW_CHOST} \
    --host=${MINGW_CHOST} \
    --with-python \
    --without-perl \
    --enable-lcms \
    --enable-poppler-cairo \
    --disable-dependency-tracking
  make
}

package() {
  cd ${srcdir}/build-${MINGW_CHOST}
  make DESTDIR="${pkgdir}" install
}
